package com.life.ai.server.modules.common.controller;

import com.life.ai.server.common.domain.R;
import com.life.ai.server.common.exception.ServiceException;
import com.life.ai.server.framework.osssts.OssStsClient;
import com.life.ai.server.framework.osssts.StsCredentials;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * FileController
 *
 * @author kylewka
 * @since 2024/6/14
 */
@Slf4j
@Api(tags = "文件存储管理")
@RestController
@RequestMapping("/common/file")
public class FileController {

    @Resource
    private OssStsClient ossStsClient;

    @ApiOperation(value = "获取直传token")
    @GetMapping("/stsToken")
    public R<StsCredentials> stsToken() {
        try {
            return R.ok(ossStsClient.getStsCredentials());
        } catch (Exception e) {
            log.error("直传token获取失败", e);
            throw new ServiceException("直传token获取失败");
        }
    }

}
